﻿/*----------------------------------------------------------------
  //Copyright (C) 2012 赵国伟
  //文件功能描述：广告管理Ajax请求服务端处理程序。
  //创建人：赵国伟
  //生成时间：2012/04/21 14:15:00
//----------------------------------------------------------------*/
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using Shopping.Common;
using Shopping.Model;
using Shopping.BLL;

public partial class Manage_AS_AdCommon : BaseManagePage
{
    private readonly ADManage bllAd = new ADManage();
    private ReturnValue ret = new ReturnValue();

    protected void Page_Load(object sender, EventArgs e)
    {
         string action = Request.QueryString["Action"] as string;
         switch (action)
         {
             case "Delete":  //删除指定的广告；
                 Delete();
                 break;
             case "Save":  //保存指定的广告；
                 Save();
                 break;
             case "GetAD":  //查询一条广告信息；
                 GetAD();
                 break;
         }
    }

    #region "删除指定的广告；"
    /// <summary>
    /// 删除指定的广告；
    /// </summary>
    private void Delete()
    {
        int ADID = Utility.G<int>("ADID");
        Response.Write(bllAd.Delete(ADID).ToJsonString());
    }
    #endregion

    #region "保存指定的广告"
    /// <summary>
    /// 保存指定的广告
    /// </summary>
    public void Save()
    {
        string jsonData = Request.Form["jsonData"] + "";
        ReturnValue ret = new ReturnValue();
        AdInfo a = new AdInfo();
        try
        {
            a = JSONHelper.JsonStringToObject<AdInfo>(jsonData);
        }
        catch(Exception e)
        {
            ret.Message = "Json反序列化失败 原因:" + e.Message;
            Response.Write(ret.ToJsonString());
            return;
        }
        Response.Write(bllAd.Save(a).ToJsonString());
    }
    #endregion

    #region "查询一条广告信息；"
    /// <summary>
    /// 查询一条广告信息；
    /// </summary>
    private void GetAD()
    {
        int adid = Utility.G<int>("ADID");
        AdInfo a = bllAd.GetAD(adid);
        if (a != null)
            Response.Write(JSONHelper.ObjectToJson<AdInfo>(a));
    }
    #endregion

}